home *** CD-ROM | disk | FTP | other *** search
- /*
- * SIGStatusWindow.c
- * Copyright © 1993 Apple Computer Inc.
- * All Rights Reserved
- *
- * Manage a status window that can be used to stop Digital Signature
- * operation. It is created when an application passes gSIGStatusProc
- * to one of the signing or verifying methods. It creates a small status
- * window with a "barber pole" progress indicator and a Cancel button.
- *
- * While a production application would define this window and its contents
- * using resources, I chose to use compiled-in values and strings to
- * keep all the information in one place.
- *
- * Note that it is rather Think C Class Library specific. In particular,
- * if you use this, you must create any windows with signable data using
- * TCL methods. In particular, you cannot "sign" from a Modal Dialog.
- * DemoSignedObjectDialog shows how a Modal Dialog may be implemented using
- * TCL classes.
- */
- #include "SIGStatusManager.h"
- #include <CApplication.h>
- #include <CBartender.h>
- #include <CDecorator.h>
- #include <CEditText.h>
- #include <CPane.h>
- #include <CButton.h>
- #include <CDesktop.h>
- #include <Commands.h>
- #include <CWindow.h>
- extern CApplication *gApplication;
- extern CBartender *gBartender;
- extern CDesktop *gDesktop;
- extern CDecorator *gDecorator;
- static Boolean gContinueSigning; /* False stops signing */
- pascal Boolean gSIGStatusProc(void);
-
- /*
- * The following variables are needed by the status procedure.
- */
- #define kStatusUpdateWait (1) /* Update frequency */
- typedef struct PatternStruct {
- Pattern aPattern;
- } PatternStruct;
-
- static PatternStruct gBarberPolePattern = {
- { 0x0F, 0x1E, 0x3C, 0x78, 0xF0, 0xE1, 0xC3, 0x87 }
- };
-
- /*
- *** Here are some classes that are used only by SIGStatusManager.
- */
- /*
- * This pane displays the "barber pole" progress info.
- */
- struct ProgressPane : CPane {
- private:
- PatternStruct itsPattern;
- public:
- void IProgressPane(
- CWindow *theWindow
- );
- void Draw(
- Rect *aRect
- );
- };
-
- /*
- * SIGStatusManager displays this window.
- */
- struct SIGStatusWindow : CWindow {
- public:
- ProgressPane *itsProgressPane;
-
- public:
- /*
- * Create the status window.
- */
- void ISIGStatusWindow(
- CDirector *aSupervisor,
- ConstStr255Param actionString,
- ConstStr255Param objectString
- );
- };
-
- /*
- * Initialize a status manager window.
- */
- void
- SIGStatusManager::ISIGStatusManager(
- ConstStr255Param actionString,
- ConstStr255Param objectString
- )
- {
- inherited::IDirector((CDirector *) gApplication);
- itsWindow = (CWindow *) new (SIGStatusWindow);
- ((SIGStatusWindow *) itsWindow)->ISIGStatusWindow(
- this,
- actionString,
- objectString
- );
- BecomeGopher(TRUE);
- itsTickCount = TickCount() + kStatusUpdateWait;
- gContinueSigning = TRUE;
- }
-
- void
- SIGStatusManager::DoCommand(
- long theCommand
- )
- {
- switch (theCommand) {
- case cmdCancel:
- gContinueSigning = FALSE;
- /* Let our supervisors see cmdCancel, too */
- default:
- inherited::DoCommand(theCommand);
- break;
- }
- }
-
- /*
- * Dawdle is called by the idle loop.
- * We draw the window directly to avoid
- * the overhead of an update event.
- */
- void
- SIGStatusManager::Dawdle(
- long *maxSleep
- )
- {
- unsigned long now;
-
- now = TickCount();
- if (now >= itsTickCount) {
- ((SIGStatusWindow *) itsWindow)
- ->itsProgressPane
- ->Prepare();
- ((SIGStatusWindow *) itsWindow)
- ->itsProgressPane
- ->Draw(NULL);
- itsTickCount += kStatusUpdateWait;
- }
- *maxSleep = itsTickCount - now;
- }
-
- /*
- * Create a status window.
- */
- void
- SIGStatusWindow::ISIGStatusWindow(
- CDirector *aSupervisor,
- ConstStr255Param actionString,
- ConstStr255Param objectString
- )
- {
- Rect bounds;
- CButton *aCancelButton;
- CEditText *someText;
-
- SetRect(&bounds, 40, 40, 360, 130);
- inherited::INewWindow(
- &bounds, /* Bounds rect */
- FALSE, /* Initially invisible */
- movableDBoxProc, /* Moveable modal dlog */
- FALSE, /* Floating window */
- FALSE, /* No goAway box */
- gDesktop, /* Enclosure */
- aSupervisor /* Supervisor */
- );
- SetWantsClicks(TRUE);
- /*
- * Create the window contents. There are three subpanes:
- * a Cancel button, progress "barber pole", and a
- * TextEdit window with the two strings.
- */
- aCancelButton = new (CButton);
- aCancelButton->INewButton(
- 60, /* Width */
- 20, /* Height */
- 250, /* Horizontal position */
- 60, /* Vertical position */
- "\pCancel", /* Text */
- TRUE, /* Visible */
- pushButProc, /* It's a button */
- this, /* Enclosure */
- this /* Supervisor */
- );
- aCancelButton->SetClickCmd(cmdCancel);
- /* */
- itsProgressPane = new (ProgressPane);
- itsProgressPane->IProgressPane(this);
- /* */
- someText = new (CEditText);
- someText->IEditText(
- this, /* Enclosure */
- this, /* Supervisor */
- 300, /* Width */
- 40, /* Height */
- 10, /* Horizontal position */
- 10, /* Vertical position */
- sizFIXEDLEFT, /* Fixed position */
- sizFIXEDTOP, /* Fixed position */
- 300 /* Line width */
- );
- someText->Specify(FALSE, FALSE, FALSE); /* Can't touch */
- someText->SetWantsClicks(FALSE);
- someText->SetCanBeGopher(FALSE); /* Really can't touch */
- someText->SetFontNumber(systemFont);
- someText->SetFontSize(12); /* System font size */
- someText->InsertTextPtr(
- (Ptr) &actionString[1], actionString[0], FALSE);
- someText->InsertTextPtr(
- (Ptr) &objectString[1], objectString[0], FALSE);
- SetModal(TRUE);
- gDecorator->CenterWindow(this);
- Select();
- }
-
- /*
- * Create the barber pole pane.
- */
- void
- ProgressPane::IProgressPane(
- CWindow *theWindow
- )
- {
- inherited::IPane(
- (CView *) theWindow, /* Enclosure */
- (CBureaucrat *) theWindow, /* Supervisor */
- 230, /* Width */
- 10, /* Height */
- 10, /* Horizontal position */
- 65, /* Vertical position */
- sizFIXEDLEFT, /* Fixed at the left */
- sizFIXEDTOP /* Fixed from the top */
- );
- itsPattern = gBarberPolePattern;
- }
-
- /*
- * Each time we draw the barber pole, we update the pattern.
- */
- void
- ProgressPane::Draw(
- Rect *theRect
- )
- {
- LongRect theAperture;
- Rect drawingRect;
- PenState penState;
- Boolean wasLocked;
- short temp;
- register short i;
- register unsigned char *thePattern;
-
- GetAperture(&theAperture);
- LongToQDRect(&theAperture, &drawingRect);
- GetPenState(&penState);
- PenNormal();
- FrameRect(&drawingRect);
- InsetRect(&drawingRect, 1, 1);
- wasLocked = Lock(TRUE);
- thePattern = itsPattern.aPattern;
- FillRect(&drawingRect, thePattern);
- /*
- * Rotate the pattern.
- */
- temp = thePattern[7];
- for (i = 7; i > 0; --i)
- thePattern[i] = thePattern[i - 1];
- thePattern[0] = temp;
- SetPenState(&penState);
- Lock(wasLocked);
- }
-
- /*
- * gSIGStatusProc is the default status procedure. It processes events
- * using the "standard" Think C event loop manager. If the global
- * gContinueSigning is FALSE, it exits immediately. Note that
- * Process1Event is wrapped in a failure environment. If you don't
- * do this, TCL will take its default failure action, which is
- * to jump to your event loop. I.e., you'll never return to
- * the Digital Signer manager. This will leave a pending mess
- * in your system that will come back to haunt you, as it did me.
- */
- pascal Boolean
- gSIGStatusProc(void)
- {
- if (gContinueSigning) {
- TRY {
- gApplication->Process1Event();
- }
- CATCH {
- NO_PROPAGATE;
- }
- ENDTRY;
- }
- return(gContinueSigning);
- }
-
-
-